package com.apestech.api.workflow.lib.app;

import com.apestech.api.workflow.lib.FlowUtil;
import com.apestech.api.workflow.lib.element.FlowExecute;
import com.apestech.api.workflow.lib.element.FlowQuery;
import com.apestech.api.workflow.lib.element.WorkProcessEngine;
import com.apestech.framework.json.JSONArray;
import com.apestech.framework.json.JSONObject;

import java.util.ArrayList;

/**
 * 其它辅助功能
 *
 * @author hup
 * @create 2018-07-21-15:15
 */
public class FlowOtherApp extends FlowUtil{

    private WorkProcessEngine engine;

    public FlowOtherApp(WorkProcessEngine engine){
        this.engine=engine;
    }

    /**
     * OA文件按目录部署
     * @param dir
     * @throws Exception
     */
    public void refreshDeployment(String dir) throws Exception {
        FlowExecute exec=new FlowExecute(engine);
        exec.setBpmnDir(dir);
        exec.refreshDeployment();
    }

    /**
     * 查询人员待办
     * @param userId
     * @return
     * @throws Exception
     */
    public JSONArray getUserToDoTask(String userId) throws Exception {
        FlowQuery query=new FlowQuery(engine);
        return query.getUserToDoTask(userId, new JSONObject());
    }

    /**
     * 根据taskId或processInstanceId获取指定结点或某个进程运行时结点下的候选人列表
     * @param input
     * @return
     * @throws Exception
     */
    public ArrayList<String> getTaskUserList(JSONObject input) throws Exception {
        String taskId=input.getString("taskId");
        if(taskId!=null){
            return this.getTaskUserList(engine,taskId);
        } else {
            TaskQueryApp qtask=new TaskQueryApp(engine, input);
            return qtask.getTaskUserList();
        }
    }

    /**
     * 根据taskId或processInstanceId获取指定结点或某个进程运行时结点下的变量信息
     * @param input
     * @return
     * @throws Exception
     */
    public JSONObject getTaskMap(JSONObject input) throws Exception {
        String taskId=input.getString("taskId");
        if(taskId!=null){
            return this.getTaskMap(engine,taskId, input);
        } else {
            TaskQueryApp qtask=new TaskQueryApp(engine, input);
            return qtask.getTaskMap();
        }
    }

}
